package com.bestcem.xm.member.dao.impl.mysql;

import com.bestcem.xm.member.dao.MemberQueryFieldDao;
import com.bestcem.xm.member.dao.mapper.MemberQueryFieldMapper;
import com.bestcem.xm.member.entity.mongo.MemberQueryField;
import com.bestcem.xm.member.entity.pojo.MemberQueryFieldDO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 示例服务
 *
 * @author yf.wang <yf.wang@idiaoyan.com>
 * @version V1.0
 * @date 2021/8/18
 */
@Repository
public class MemberQueryFieldDaoImpl implements MemberQueryFieldDao {

    @Resource
    private MemberQueryFieldMapper memberQueryFieldMapper;

    @Override
    public MemberQueryFieldDO findOneByOrgIdAndMemberType(Integer attribute, String orgId) {
        return memberQueryFieldMapper.findOneByOrgIdAndAttribute(orgId, attribute);
    }

    @Override
    public void createMemberQueryField(MemberQueryFieldDO memberQueryField) {
        memberQueryFieldMapper.createMemberQueryField(memberQueryField);
    }

    @Override
    public void updateMemberQueryField(MemberQueryFieldDO memberQueryField) {
        memberQueryFieldMapper.updateMemberQueryField(memberQueryField);
    }

    @Override
    public List<MemberQueryFieldDO> findAll(int offset, int batchSize) {
        return memberQueryFieldMapper.findAll(offset, batchSize);
    }

    @Override
    public void updateBaseQueryField(String id, String baseFields) {
        memberQueryFieldMapper.updateBaseQueryField(id, baseFields);
    }

    private MemberQueryFieldDO convert(MemberQueryField queryField){
        MemberQueryFieldDO entity = new MemberQueryFieldDO();
        entity.setId(queryField.getId());
        entity.setOrgId(queryField.getOrgId());
        entity.setMemberType(queryField.getMemberType());
        if(queryField.getBaseFields() != null){
            entity.setBaseFields(queryField.getBaseFields().toString());
        }
        if(queryField.getExtendFields() != null){
            entity.setBaseFields(queryField.getExtendFields().toString());
        }
        entity.setCreateTime(queryField.getCreateTime());
        entity.setUpdateTime(queryField.getUpdateTime());
        return entity;
    }
}
